<template>
  <el-container>
    <!-- 头部区域 -->
    <el-header>
      <el-row>
        <el-col :span="1">
          <div class="imgbox">
            <img src="../assets/myLogo.jpg" alt="" />
          </div>
        </el-col>
        <el-col :span="21">后台管理系统</el-col>
        <el-col :span="2">
          <el-button type="info" @click="exitLogin">退出</el-button></el-col
        >
      </el-row>
    </el-header>
    <!-- 主体区域  -->
    <el-container>
      <!-- 侧边栏  -->
      <el-aside :width="isCollapse ? 64 +'px' : 200 + 'px'">
          <div class="toggle_button" @click="toggleCollapse">| | |</div>
        <!-- 侧边栏菜单区 -->        
        <el-menu
          background-color="#313743"
          text-color="#fff"
          active-text-color="#3b9af9"
          unique-opened
          :collapse='isCollapse'
          :collapse-transition = 'false'
          router
        >        
          <!-- 一级菜单区域   -->
          <el-submenu :index="i+''" v-for="(item,i) in menuList" :key="item.id">
            <!-- 一级菜单模板区域 -->
            <template slot="title">
              <!-- 图标 -->
              <i :class="iconsObj[item.id]"></i>
              <!-- 文本 -->
              <span>{{item.authName}}</span>
            </template>
            <!-- 二级菜单区域 -->
            <el-menu-item :index="item1.path" v-for="item1 in item.children" :key="item1.id">
              <i class="el-icon-menu"></i>{{item1.authName}}
            </el-menu-item>
          </el-submenu>
        </el-menu>
      </el-aside>
      <!-- 右侧区域 -->
      <el-main><router-view></router-view></el-main>
    </el-container>
  </el-container>
</template>

<script>
export default {
  name: "",
  created() {
    this.getMenuList();
  },
  data() {
    return {
      menuList: [],
      iconsObj:{
          '125':'iconfont icon-renyuan',
          '103':'iconfont icon-shikong-kongjianxuanzhong',
          '101':'iconfont icon-shangpin',
          '102':'iconfont icon-danju-tianchong',
          '145':'iconfont icon-baobiao',
      },
      isCollapse:false
    };
  },
  methods: {
    exitLogin() {
      window.sessionStorage.clear();
      this.$router.push("/login");
      this.$message({ message: "退出成功", type: "success" });
    },
    //获取所有菜单
    getMenuList() {
      this.$http.get("menus").then(res => {
        // console.log(res);
        const { meta, data } = res.data;
        if (meta.status !== 200) return this.$message.error("菜单列表获取失败");
        this.$message({ message: meta.msg, type: "success" });
        this.menuList = data;
        console.log(this.menuList);
      });
    },
    // 折叠菜单
    toggleCollapse(){
        this.isCollapse = !this.isCollapse;
    }
  },
  components: {}
};
</script>

<style lang='less' scpoed>
.el-container {
  height: 100%;
  .el-header {
    background-color: #363d40;
    padding: 0;
    .el-row {
      height: 100%;
      position: relative;
      .el-col {
        height: 100%;
      }
      .el-col-21 {
        padding: 0 0 0 20px;
        color: #fff;
        font-size: 16px;
        display: flex;
        align-items: center;
        justify-content: flex-start;
      }
      .el-col-2 {
        display: flex;
        align-items: center;
        justify-content: flex-start;
      }
    }
    .imgbox {
      img {
        height: 100%;
        position: absolute;
        top: 0;
        left: 0;
        border-radius: 50%;
      }
    }
  }
  .el-aside {
    background-color: #313743;
  }
  .el-main {
    background-color: #e9edf1;
  }
  .iconfont{
      margin-right: 10px;
  }
  .el-menu {
    border-right: none;
  }
  .toggle_button{
      color: #fff;
      background-color:#465263;
      text-align: center;
      line-height: 23px;
      font-size: 6px;    
      cursor: pointer;
  }
}
</style>
